load("@bazel_gomock//:gomock.bzl", "gomock")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
    name = "log",
    srcs = [
        "ambient_context.go",
        "buffered_sink.go",
        "buffered_sink_closer.go",
        "channels.go",
        "clog.go",
        "doc.go",
        "event_log.go",
        "every_n.go",
        "exit_override.go",
        "file.go",
        "file_api.go",
        "file_log_gc.go",
        "file_names.go",
        "file_sync_buffer.go",
        "flags.go",
        "fluent_client.go",
        "format_crdb.go",
        "format_crdb_v1.go",
        "format_crdb_v2.go",
        "format_json.go",
        "formats.go",
        "formattable_tags.go",
        "http_sink.go",
        "intercept.go",
        "log.go",
        "log_bridge.go",
        "log_buffer.go",
        "log_decoder.go",
        "log_entry.go",
        "log_flush.go",
        "metric.go",
        "redact.go",
        "registry.go",
        "report.go",
        "sinks.go",
        "stderr_redirect.go",
        "stderr_redirect_unix.go",
        "stderr_redirect_windows.go",
        "stderr_sink.go",
        "structured.go",
        "structured_processor.go",
        "structured_v2.go",
        "test_log_scope.go",
        "trace.go",
        "tracebacks.go",
        "vmodule.go",
        ":gen-log-channels",  # keep
    ],
    importpath = "github.com/cockroachdb/cockroach/pkg/util/log",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/base/serverident",
        "//pkg/build",
        "//pkg/cli/exit",
        "//pkg/settings",
        "//pkg/testutils/skip",
        "//pkg/util",
        "//pkg/util/allstacks",
        "//pkg/util/caller",
        "//pkg/util/encoding/encodingtype",
        "//pkg/util/envutil",
        "//pkg/util/fileutil",
        "//pkg/util/httputil",
        "//pkg/util/jsonbytes",
        "//pkg/util/log/channel",
        "//pkg/util/log/logconfig",
        "//pkg/util/log/logflags",
        "//pkg/util/log/logpb",
        "//pkg/util/log/severity",
        "//pkg/util/syncutil",
        "//pkg/util/sysutil",
        "//pkg/util/timeutil",
        "//pkg/util/tracing",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_errors//oserror",
        "@com_github_cockroachdb_logtags//:logtags",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_cockroachdb_redact//interfaces",
        "@com_github_cockroachdb_ttycolor//:ttycolor",
        "@com_github_petermattis_goid//:goid",
    ] + select({
        "@io_bazel_rules_go//go/platform:aix": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:android": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:darwin": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:dragonfly": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:freebsd": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:illumos": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:ios": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:js": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:linux": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:netbsd": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:openbsd": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:plan9": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:solaris": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:windows": [
            "@org_golang_x_sys//windows",
        ],
        "//conditions:default": [],
    }),
)

go_test(
    name = "log_test",
    size = "medium",
    srcs = [
        "ambient_context_test.go",
        "buffered_sink_closer_test.go",
        "buffered_sink_test.go",
        "channels_test.go",
        "clog_test.go",
        "file_log_gc_test.go",
        "file_names_test.go",
        "file_test.go",
        "flags_test.go",
        "fluent_client_test.go",
        "format_crdb_v1_test.go",
        "format_crdb_v2_test.go",
        "format_json_test.go",
        "formats_test.go",
        "formattable_tags_test.go",
        "helpers_test.go",
        "http_sink_test.go",
        "intercept_test.go",
        "log_decoder_test.go",
        "main_test.go",
        "redact_test.go",
        "registry_test.go",
        "secondary_log_test.go",
        "test_log_scope_test.go",
        "trace_client_test.go",
        "trace_test.go",
        ":mock_logsink",  # keep
    ],
    data = glob(["testdata/**"]),
    embed = [":log"],
    deps = [
        "//pkg/base/serverident",
        "//pkg/build",
        "//pkg/cli/exit",
        "//pkg/settings/cluster",
        "//pkg/util/caller",
        "//pkg/util/ctxgroup",
        "//pkg/util/leaktest",
        "//pkg/util/log/channel",
        "//pkg/util/log/logconfig",
        "//pkg/util/log/logpb",
        "//pkg/util/log/severity",
        "//pkg/util/randutil",
        "//pkg/util/syncutil",
        "//pkg/util/timeutil",
        "//pkg/util/tracing",
        "//pkg/util/tracing/tracingpb",
        "@com_github_cockroachdb_datadriven//:datadriven",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_logtags//:logtags",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_golang_mock//gomock",  # keep
        "@com_github_kr_pretty//:pretty",
        "@com_github_pmezard_go_difflib//difflib",
        "@com_github_stretchr_testify//assert",
        "@com_github_stretchr_testify//require",
        "@org_golang_x_sys//unix",
    ],
)

genrule(
    name = "gen-log-channels",
    srcs = [
        "//pkg/util/log/logpb:log.proto",
    ],
    outs = ["log_channels_generated.go"],
    cmd = """
        $(location //pkg/util/log/gen) $(location //pkg/util/log/logpb:log.proto) \
          log_channels.go $(location log_channels_generated.go)
       """,
    tools = [
        "//pkg/util/log/gen",
    ],
    visibility = [
        ":__pkg__",
        "//pkg/gen:__pkg__",
    ],
)

gomock(
    name = "mock_logsink",
    out = "mocks_generated_test.go",
    interfaces = [
        "TestingLogSink",
    ],
    library = ":log",
    mock_names = {"TestingLogSink": "MockLogSink"},
    package = "log",
    self_package = "github.com/cockroachdb/cockroach/pkg/util/log",
    visibility = [
        ":__pkg__",
        "//pkg/gen:__pkg__",
    ],
)
